package com.ruoyi.web.controller.wnjk.hospital;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.wnjk.domain.po.WnjkHospital;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.wnjk.service.IWnjkHospitalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 医院信息Controller
 *
 * @author ruoyi
 * @date 2025-03-06
 */
@RestController
@RequestMapping("/hospital/hospital")
public class WnjkHospitalController extends BaseController
{
    @Autowired
    private IWnjkHospitalService wnjkHospitalService;

    /**
     * 查询医院信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospital:list')")
    @GetMapping("/list")
    public TableDataInfo list(WnjkHospital wnjkHospital)
    {
        startPage();
        List<WnjkHospital> list = wnjkHospitalService.selectWnjkHospitalList(wnjkHospital);
        return getDataTable(list);
    }

    /**
     * 导出医院信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospital:export')")
    @Log(title = "医院信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WnjkHospital wnjkHospital)
    {
        List<WnjkHospital> list = wnjkHospitalService.selectWnjkHospitalList(wnjkHospital);
        ExcelUtil<WnjkHospital> util = new ExcelUtil<WnjkHospital>(WnjkHospital.class);
        util.exportExcel(response, list, "医院信息数据");
    }

    /**
     * 获取医院信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospital:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wnjkHospitalService.selectWnjkHospitalById(id));
    }

    /**
     * 新增医院信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospital:add')")
    @Log(title = "医院信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WnjkHospital wnjkHospital)
    {
        return toAjax(wnjkHospitalService.insertWnjkHospital(wnjkHospital));
    }

    /**
     * 修改医院信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospital:edit')")
    @Log(title = "医院信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WnjkHospital wnjkHospital)
    {
        return toAjax(wnjkHospitalService.updateWnjkHospital(wnjkHospital));
    }

    /**
     * 删除医院信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospital:remove')")
    @Log(title = "医院信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wnjkHospitalService.deleteWnjkHospitalByIds(ids));
    }
}
